package com.zmn.oms.common.discount.impl;

import com.zmn.common.constant.FicoConsts;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.common.discount.dto.CalculateDiscountListDTO;
import com.zmn.oms.common.discount.dto.CalculateDiscountResultDTO;
import com.zmn.oms.common.discount.interfaces.DiscountCalculator;
import com.zmn.oms.common.dto.ResultDTO;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * 类描述：工程师优惠
 *
 * @author heciqi
 * @date 2018/12/08 10:34
 */
public class MasterDiscountCalculatorImpl extends AbsDiscountCalculatorImpl{

	/**
	 * 是否能优惠
	 *
	 * @param origDiscounts 优惠列表
	 * @return
	 */
	@Override
	public ResultDTO canDiscount(List<CalculateDiscountListDTO> origDiscounts) {

		if (CollectionUtils.isEmpty(origDiscounts)) {
			return new ResultDTO(true);
		} else {
			boolean match = origDiscounts.stream().anyMatch(e -> e.getCateg() == FicoConsts.ORDER_IN_DISCOUNT_CATEG_ARTIFICIAL_OPERATOR);
			if (match) {
				return new ResultDTO(false, "已经存在后台人工优惠，不能再次优惠");
			} else {
				return new ResultDTO(true);
			}
		}
	}

	/**
	 * 计算优惠金额
	 *
	 * @param origDiscounts 原有优惠列表
	 * @param initialAmount 初始金额（在该金额基础上计算优惠）
	 * @param calculator    回调实现各自计算
	 * @return 返回计算模型
	 */
	@Override
	public CalculateDiscountResultDTO calculate(List<CalculateDiscountListDTO> origDiscounts, Integer initialAmount, DiscountCalculator calculator) {
		CalculateDiscountResultDTO discountResultDTO = super.calculate(origDiscounts, initialAmount, calculator);

		discountResultDTO.setDiscountType(OrderConsts.ORDER_DISCOUNT_TYPE_LIMIT_FREE);
		discountResultDTO.setRemark("工程师9折优惠");
		return discountResultDTO;
	}
}
